﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using XbsWebAPI.Application;
using XbsWebAPI.Application.CampRoom.Dtos;
using XbsWebAPI.Application.QueryModel;

namespace XbsWebAPI.MainHost.Controllers
{
    /// <summary>
    /// 配套服务
    /// </summary>
    [ApiController]
    [Route("api/xbs_v1/[controller]")]
    public class SupportingFacilityController : Controller
    {
        private readonly ISupportingFacilityAppService _supportingFacilityAppService;

        public SupportingFacilityController(ISupportingFacilityAppService supportingFacilityAppService)
        {
            _supportingFacilityAppService = supportingFacilityAppService;
        }

        /// <summary>
        /// 新建 配套服务
        /// </summary>
        /// <param name="model">配套服务 入参</param>
        /// <returns></returns>
        [HttpPost]
        [Route("[action]")]
        public async Task<ResultDto<string>> AddSupportingFacility(CreateSupportingFacilityDto model)
        {
            var result = await _supportingFacilityAppService.CreateSupportingFacilityAsync(model);
            return result;
        }

        /// <summary>
        /// 更新 配套服务
        /// </summary>
        /// <param name="model">配套服务 入参</param>
        /// <returns></returns>
        [HttpPost]
        [Route("[action]")]
        public async Task<ResultDto<string>> EditSupportingFacility(EditSupportingFacilityDto model)
        {
            var result = await _supportingFacilityAppService.UpdateSupportingFacilityAsync(model);
            return result;
        }

        /// <summary>
        /// 删除 配套服务
        /// </summary>
        /// <param name="id">配套服务Id</param>
        /// <returns></returns>
        [HttpGet]
        [Route("[action]")]
        public async Task<ResultDto<string>> DeleteSupportingFacility(Guid id)
        {
            var result = await _supportingFacilityAppService.RemoveSupportingFacilityAsync(id);
            return result;
        }

        /// <summary>
        /// 分页查询配套服务
        /// </summary>
        /// <param name="name">配套服务名称</param>
        /// <param name="pageNumber">第几页，默认1</param>
        /// <param name="pageSize">每页多少条，默认10</param>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<PageListDto<ListSupportingFacility>> FindSupportingFacilityPagedList(string name, int? pageNumber, int? pageSize)
        {
            QuerySupportingFacility query = new QuerySupportingFacility
            {
                Name = name,
                PageNumber = pageNumber,
                PageSize = pageSize
            };
            var result = _supportingFacilityAppService.GetSupportingFacilityPagedList(query);

            return result;
        }

        /// <summary>
        /// 查询所有配套服务
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ResultDto<List<ListSupportingFacility>> FindSupportingFacilityList()
        {
            var result = _supportingFacilityAppService.GetSupportingFacilityList();

            return result;
        }
    }
}
